package com.exam.controller;
import com.exam.entity.JudgeQuestion;
import com.exam.service.JudgeQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/judge-questions")
public class JudgeQuestionController {

    @Autowired
    private JudgeQuestionService judgeQuestionService;

    @PostMapping
    public JudgeQuestion addJudgeQuestion(@RequestBody JudgeQuestion judgeQuestion) {
        return judgeQuestionService.addJudgeQuestion(judgeQuestion);
    }

    @PutMapping("/{id}")
    public JudgeQuestion updateJudgeQuestion(@PathVariable Long id, @RequestBody JudgeQuestion judgeQuestion) {
        return judgeQuestionService.updateJudgeQuestion(id, judgeQuestion);
    }

    @DeleteMapping("/{id}")
    public void deleteJudgeQuestion(@PathVariable Long id) {
        judgeQuestionService.deleteJudgeQuestion(id);
    }

    @GetMapping("/{id}")
    public JudgeQuestion getJudgeQuestionById(@PathVariable Long id) {
        return judgeQuestionService.getJudgeQuestionById(id);
    }

    @GetMapping
    public List<JudgeQuestion> getAllJudgeQuestions() {
        return judgeQuestionService.getAllJudgeQuestions();
    }

    @PostMapping("/import")
    public void importJudgeQuestions(@RequestBody List<JudgeQuestion> judgeQuestions) {
        judgeQuestionService.importJudgeQuestions(judgeQuestions);
    }

    @PostMapping("/check-duplicate")
    public boolean checkDuplicate(@RequestBody JudgeQuestion judgeQuestion) {
        return judgeQuestionService.checkDuplicate(judgeQuestion);
    }
    @GetMapping("/paged")
    public Page<JudgeQuestion> getAllJudgeQuestionsPaged(
            @RequestParam(defaultValue = "0") int page, // 当前页
            @RequestParam(defaultValue = "10") int size // 每页大小
    ) {
        Pageable pageable = PageRequest.of(page, size);
        return judgeQuestionService.getAllJudgeQuestions(pageable);
    }

}